//
//  SLMineVC.swift
//  sulit-loan
//
//  Created by 王刚锋 on 2025/4/5.
//  Copyright © 2025 coolBoy. All rights reserved.
//

import UIKit
import DCURLRouter
import SwiftyJSON

class SLMineVC: SLTableVC<Any> {

    var dataArray:[JSON] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.refreshAction()
        
    }
    override func refreshData(isPullDown: Bool = true) {
        SLHttpTool.AsyncReportData(path: "/satisfies/raises", target: self) { responseCall, success, msg, code in
            self.tableview.mj_header?.endRefreshing()
            let data = responseCall["wavelets"]
            self.headView.headView.setUrlImage(url: data["userInfo"]["finish"].stringValue,placeholder: IMAGE("icn_head"))
            self.headView.name.text = data["userInfo"]["userphone"].stringValue
            self.dataArray.removeAll()
             let arr = data["quite"].arrayValue
                for json in arr {
                    self.dataArray.append(json)
                }
            self.tableview.reloadData()
        }

    }
    private func setupUI() {
        view.backgroundColor = .white
        self.tableview.mj_footer = nil
        self.tableview.bounces = false
        self.configAutoHeight(estimatedHeight: 44,autoPullDown: false,nibName: "SLMineCell")
        self.tableview.tableHeaderView = self.headView
        self.tableview.snp.makeConstraints { make in
            make.left.right.top.equalTo(0)
            make.bottom.equalTo(-49)
        }
        
    }
    lazy private var headView:SLMineHeadView = {
        let v = kLoadXib(xibName: "SLMineHeadView") as! SLMineHeadView
        v.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: 320)
        return v
    }()
    override func numberOfSections(in tableView: UITableView) -> Int {
        return dataArray.count
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "SLMineCell", for: indexPath) as! SLMineCell
        cell.titleL.text = dataArray[indexPath.section]["himalayas"].stringValue
        cell.icon.setUrlImage(url:dataArray[indexPath.section]["greece"].stringValue,placeholder: IMAGE("icon1"))
        cell.selectionStyle = .none
        return cell
    }
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 26
    }
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        jump(url: dataArray[indexPath.section]["imitate"].stringValue )
    }
    
}

